package handle

import (
	"context"
	pb "week3zk-project/rpc/api/goods"
	"week3zk-project/rpc/internal/model"
)

// 定义空接口

type GoodsInfoService struct {
	pb.UnimplementedGoodsServer
}

func (s *GoodsInfoService) GoodsCreate(ctx context.Context, req *pb.GoodsCreateRequest) (*pb.GoodsCreateResponse, error) {
	g := model.Goods{
		GoodsImg:    req.GoodsImg,
		GoodsTitle:  req.GoodsTitle,
		GoodsPrice:  float64(req.GoodsPrice),
		GoodsStock:  req.GoodsStock,
		SalesVolume: req.SalesVolume,
		Status:      req.Status,
	}
	err := g.Create()
	if err != nil {
		return &pb.GoodsCreateResponse{
			Code: 400,
			Msg:  "商品创建失败",
		}, err
	}
	return &pb.GoodsCreateResponse{
		Code: 200,
		Msg:  "商品创建成功",
		Id:   int64(g.ID),
	}, nil
}

//func (s *GoodsInfoService) GoodsList(ctx context.Context, req *pb.GoodsListRequest) (*pb.GoodsListResponse, error) {
//	//g:=model.Goods{
//	//	Model:       gorm.Model{},
//	//	GoodsImg:    "",
//	//	GoodsTitle:  "",
//	//	GoodsPrice:  0,
//	//	GoodsStock:  0,
//	//	SalesVolume: 0,
//	//	Status:      "",
//	//}
//}
